﻿(function($) {
    $.extend({
        format : function(str, step, splitor) {
            str = str.toString();
            var len = str.length;

            if(len > step) {
                var l1 = len%step,
                    l2 = parseInt(len/step),
                    arr = [],
                    first = str.substr(0, l1);
                if(first != '') {
                    arr.push(first);
                };
                for(var i=0; i<l2 ; i++) {
                    arr.push(str.substr(l1 + i*step, step));
                };
                str = arr.join(splitor);
            };
            return str;
        }
    });
})(jQuery);
(function ($) {
    if (!$.setCookie) {
        $.extend({
            setCookie: function (c_name, value, exdays) {
                try {
                    if (!c_name) return false;
                    var exdate = new Date();
                    exdate.setDate(exdate.getDate() + exdays);
                    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()+";path=/");
                    document.cookie = c_name + "=" + c_value;
                }
                catch (err) {
                    return '';
                };
                return '';
            }
        });
    };
    if (!$.getCookie) {
        $.extend({
            getCookie: function (c_name) {
                try {
                    var i, x, y,
                        ARRcookies = document.cookie.split(";");
                    for (i = 0; i < ARRcookies.length; i++) {
                        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
                        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
                        x = x.replace(/^\s+|\s+$/g, "");
                        if (x == c_name) return (y);
                    };
                }
                catch (err) {
                    return '';
                };
                return '';
            }
        });
    };
})(jQuery);
jQuery(document).ready(function() {
    jQuery(".navbar-menu").click(function() {
        jQuery(".navbar-menu").toggleClass("closed");
       //jQuery(".navbar-bottom").hasClass("open")? $(".navbar-bottom").removeClass("open"):$(".navbar-bottom").addClass("open");
        $(".navbar-bottom").toggleClass("open");
    });
    jQuery(".navbar-menu").hover(function() {
        jQuery(this).children("span").addClass("menu-icon");
    }, function() {
        jQuery(this).children("span").removeClass("menu-icon");
    });

}); 
function opendetail(m,n){
    //����
    //tomnCount(m,n,0);
    var url="/m/"+m+"/"+n;
    //kwplus();
    var _url=urlOperation(url);//url.replace("%","%25");
    //window.open(_url);
    location.href=_url;
}
function searchopendetail(m,n){
    var url="/m/"+m+"/"+n+"?t=s";
    var _url=urlOperation(url);//url.replace("%","%25");
    $("#myifrmae iframe").attr("src",_url);
    moveBox();
}
function urlOperation(url){
	return url.replace("%","%25").replace("#","%23").replace("&","%26");//.replace("/","%2F"); 
}
function StringBuffer(){
    this._strings_=new Array;
};
StringBuffer.prototype.append=function(str){
    this._strings_.push(str);
};
StringBuffer.prototype.toString=function(){
    return this._strings_.join("");
};
function ToCDB(str) { 
	var tmp = ""; 
	for(var i=0;i<str.length;i++) { 
		if(str.charCodeAt(i)>65248&&str.charCodeAt(i)<65375) { 
			tmp += String.fromCharCode(str.charCodeAt(i)-65248); 
		} else { 
			tmp += String.fromCharCode(str.charCodeAt(i)); 
		} 
	} 
	return tmp;
}
    function checkchar(v){
        var Regx=/^[A-Za-z0-9]*jQuery/;
        if(Regx.test(v)){return true;}
        else{return false;}
    }
    function checkChinese(str){
        var Regx=new RegExp("[\\u4E00-\\u9FFF]+","g");
        return Regx.test(str);
    }
    function isHanzi(v){
        var patrn=/[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi;
        if(!patrn.exec(v))
            return false;
        return true;
    }
    (function(jQuery) {
        jQuery.extend({
            format : function(str, step, splitor) {
                str = str.toString();
                var len = str.length;

                if(len > step) {
                    var l1 = len%step,
                            l2 = parseInt(len/step),
                            arr = [],
                            first = str.substr(0, l1);
                    if(first != '') {
                        arr.push(first);
                    };
                    for(var i=0; i<l2 ; i++) {
                        arr.push(str.substr(l1 + i*step, step));
                    };
                    str = arr.join(splitor);
                };
                return str;
            }
        });
    })(jQuery);

function backbtn(){
    var url=document.referrer;
    if(url.indexOf("easyds.cn")>-1|| url.indexOf("222")>-1){
        window.location=url;
    }else{
        window.location= "/m";
    }
}

//退出
function uLogout(){
    var _url=window.location.href;
    $.ajax({
        type: "post",
        url: "/m/user_logout.do",
        data: "date=" + new Date().getTime(),
        dataType: "json",
        success: function(msg) {
            $.setCookie("USERLOGOUTTIME", "user logout",3);
//            //$.setCookie("USERINFO", "",3);
//            //修改顶部菜单
//            var _str="";
//            _str+=" <a href=\"javascript:void(0);\" onclick=\"ShowTopDiv('TopDiv','TopContentLogin');checkLogin(1);\">用户登录</a>";
//            $(".navbar .container .navbar-right li:eq(1)").html(_str).removeClass("userMenusShow");
//            var _url=window.location.href;
//            if(_url.length>10){
//                location.reload();
//            }
            $(".navbar-bottom li:eq(2) a img").attr("src",$(".navbar-bottom li:eq(2) a img").attr("src").replace("user2.png","user.png"));
            $(".navbar-bottom li:eq(2) span").text("登录");

            if(_url.indexOf("/active")>-1){
                 window.location.href="/m";return;
            }else{
                window.location.href="/m";return;
            }
        }
    });

//    if(_url.indexOf("/active")>-1){
//         window.location.href="/m";return;
//    }else{
//        //location.reload();
//    }

}
function valid_email(strMail) {
	if(strMail.length==0) return false ;
	var objReg = new RegExp("[a-z0-9-_]+@[a-z0-9-_]+[\.]{1}(com|net|bta|cn|org|edu|mil|hk|me|co|cc)","gi") ;
	var IsRightFmt = objReg.test(strMail) ;
	var objRegErrChar = new RegExp("[^a-z0-9-._@]","ig") ;
	var IsRightChar = (strMail.search(objRegErrChar)==-1) ;
	var IsRightLength = strMail.length <= 60 ;
	var IsRightPos = (strMail.indexOf("@",0) != 0 && strMail.indexOf(".",0) != 0 && strMail.lastIndexOf("@")+1 != strMail.length && strMail.lastIndexOf(".")+1 != strMail.length) ;
	var IsNoDupChar = (strMail.indexOf("@",0) == strMail.lastIndexOf("@")) ;
	return (IsRightFmt && IsRightChar && IsRightLength && IsRightPos && IsNoDupChar) ;
};

function gosearch(){
    window.location.href="/m?s=";
}

